import java.util.Random;
import java.util.concurrent.*;

/**
 * 实现有返回值的线程池
 */
public class ThreadPoolDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool=  Executors.newFixedThreadPool(5);
        FutureTask<Integer> result= (FutureTask<Integer>) threadPool.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int num=new Random().nextInt(10);
                System.out.println("生成随机数："+num);
                return num;
            }
        });
        System.out.println("得到线程池返回结果:"+result.get());
    }
}
